{{!

  Copyright (c) Meta Platforms, Inc. and affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

}}{{!

This is a template for exposing cpp structs and unions in .pxd

}}
{{#program:filtered_structs}}
{{#first?}}
cdef extern from "{{program:include_prefix}}{{program:cpp_gen_path}}/{{program:name}}_metadata.h" namespace "apache::thrift::detail::md":
    cdef cppclass ExceptionMetadata[T]:
        @staticmethod
        void gen(__fbthrift_cThriftMetadata &metadata)
cdef extern from "{{program:include_prefix}}{{program:cpp_gen_path}}/{{program:name}}_metadata.h" namespace "apache::thrift::detail::md":
    cdef cppclass StructMetadata[T]:
        @staticmethod
        void gen(__fbthrift_cThriftMetadata &metadata)
cdef extern from "{{program:include_prefix}}{{program:cpp_gen_path}}/{{program:name}}_types_custom_protocol.h"{{!
}} namespace "{{#program:cppNamespaces}}::{{value}}{{/program:cppNamespaces}}":
{{/first?}}
    {{#struct:union?}}
    cdef enum class {{> types/c_struct }}__type "::{{#program:cppNamespaces}}{{value}}::{{/program:cppNamespaces}}{{struct:name}}::Type":
        __EMPTY__,
    {{#struct:py3_fields}}
        {{field:py_name}},
    {{/struct:py3_fields}}
    {{/struct:union?}}

    cdef cppclass {{> types/c_struct }} "::{{#program:cppNamespaces}}{{value}}::{{/program:cppNamespaces}}{{struct:name}}"{{#struct:exception?}}(cTException){{/struct:exception?}}:
        {{> types/c_struct }}() except +
        {{^struct:cpp_noncopyable?}}
        {{> types/c_struct }}(const {{> types/c_struct }}&) except +
        {{/struct:cpp_noncopyable?}}
        {{^struct:cpp_noncomparable}}
        bint operator==({{> types/c_struct }}&)
        bint operator!=({{> types/c_struct }}&)
        {{#struct:is_struct_orderable?}}
        bint operator<({{> types/c_struct }}&)
        bint operator>({{> types/c_struct }}&)
        bint operator<=({{> types/c_struct }}&)
        bint operator>=({{> types/c_struct }}&)
        {{/struct:is_struct_orderable?}}
        {{/struct:cpp_noncomparable}}
    {{^struct:union?}}
    {{#struct:py3_fields}}
        {{#field:has_ref_accessor?}}
        {{#field:optional?}}
        __optional_field_ref[{{#field:type}}{{> types/cython_cpp_struct_field_type}}{{/field:type}}] {{!
            }}{{field:py_name}}_ref "{{> types/field_cppname}}" ()
        {{/field:optional?}}
        {{#field:required?}}
        __required_field_ref[{{#field:type}}{{> types/cython_cpp_struct_field_type}}{{/field:type}}] {{!
            }}{{field:py_name}}_ref "{{> types/field_cppname}}" ()
        {{/field:required?}}
        {{#field:unqualified?}}
        __field_ref[{{#field:type}}{{> types/cython_cpp_struct_field_type}}{{/field:type}}] {{!
            }}{{field:py_name}}_ref "{{> types/field_cppname}}" ()
        {{/field:unqualified?}}
        {{#field:terse?}}
        __terse_field_ref[{{#field:type}}{{> types/cython_cpp_struct_field_type}}{{/field:type}}] {{!
            }}{{field:py_name}}_ref "{{> types/field_cppname}}" ()
        {{/field:terse?}}
        {{/field:has_ref_accessor?}}
        {{^field:has_ref_accessor?}}
        {{#field:reference?}}
        {{#field:type}}{{> types/cython_cpp_struct_field_type}}{{/field:type}} {{field:py_name}}_ref "{{> types/field_cppname}}" ()
        {{/field:reference?}}
        {{/field:has_ref_accessor?}}
    {{/struct:py3_fields}}
    {{/struct:union?}}
    {{#struct:union?}}
        {{> types/c_struct }}__type getType() const
    {{#struct:py3_fields}}
        {{^field:has_ref_api?}}
        __union_field_ref[{{#field:type}}{{> types/cython_cpp_struct_field_type}}{{/field:type}}] {{!
            }}{{field:py_name}}_ref"{{> types/field_cppname}}_ref" ()
        {{/field:has_ref_api?}}{{!
        }}{{#field:has_ref_api?}}
        {{#field:type}}const {{> types/cython_cpp_struct_field_type}}& get_{{field:py_name}} "get_{{field:cppName}}" () const{{/field:type}}
        {{! Note that the set methods don't take in a shared/unique_ptr, they just take in an object ref,
            but they return the appropriate ptr }}
        {{#field:type}}{{> types/cython_cpp_struct_field_type}}& set_{{field:py_name}} "set_{{field:cppName}}" (const {{> types/cython_cpp_type}}&){{/field:type}}
        {{/field:has_ref_api?}}
    {{/struct:py3_fields}}{{/struct:union?}}

{{/program:filtered_structs}}
